function Game(ele) {// element 元素/节点

    // 0.保存地图对象
    this.ele = document.querySelector(ele)

    // 1. 搞地图 
    this.map = new Map(this.ele) //将地图标签对象传递给map构造函数，里面设置宽度高度等
    this.map.create()

    this.food = new Food(this.ele)
    this.food.create()

    this.snake = new Snake(this.ele)
    this.snake.create()
    this.t =null
}
Game.prototype.start = function () {
    this.t = setInterval(() => {
        this.snake.Move()
        //判断吃食：当蛇头的位置和事物的位置重合
        let snakeX = this.snake.snakeObj[0].x *20
        let snakeY = this.snake.snakeObj[0].y *20
        console.log(snakeX,snakeY);
      
        let foodsX = this.food.foodX
        let foodsY = this.food.foodY
        
        if(snakeX == foodsX && snakeY == foodsY){
             let last = this.snake.snakeObj[this.snake.snakeObj.length -1]
            //蛇增加一个div 到数组里去，push
            this.snake.snakeObj.push({
                x: last.x, y: last.y, color: last.color, ele: null
            })
             //重新绘制蛇
         this.snake.create()
         this.food.Move()
        }
      console.log(snakeX,snakeY);
       
        if(snakeX >  this.map.width -this.snake.len || snakeY >=  this.map.height -this.snake.len || snakeX < 0 || snakeY < 0 ){
            alert('你撞墙了')
            clearInterval(this.t)
            location.reload()
            
        }
 
    }, 150)
   
    //监控页面按下的键
    document.addEventListener('keydown', (e) => {
        //获取事件对象
        e = e || window.event
        //获取键盘
       // console.log(e.keyCode);//37 38 39 40 左上右下
        switch (e.keyCode) {
            case 37:
                this.snake.direction = 'left'
                break;
            case 38:
                this.snake.direction = 'top'
                break;
            case 39:
                this.snake.direction = 'right'
                break;
            case 40:
                this.snake.direction = 'bottom'
                break;
            default:
                break;
        }

    })
   let start = document.querySelector('.start').disabled = true
   
}
Game.prototype.stop =function(){
     clearInterval(this.t)
     let start = document.querySelector('.start').disabled = false
}

